<template>
  <div class="avue-crud">
    <el-table :data="dataList" :height="tableHeight==null?'calc((100vh - 80px - 70px) / 2 - 60px)':tableHeight" border>
      <el-table-column label="流程类别" prop="type" align="center" min-width="120px">
        <template slot-scope="scope">
          <span v-if="scope.row.type=='JJ_FP'">奖金审核</span>
          <span v-else>发放审核</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="当前节点" prop="taskName" align="center" min-width="120px"></el-table-column>-->
      <!-- <el-table-column label="接收时间" prop="time" align="center" min-width="150px">
        <template slot-scope="scope">{{$moment(scope.row.time).format("YYYY-MM-DD HH:mm")}}</template>
      </el-table-column> -->
      <el-table-column label="当前节点" prop="taskName" align="center" width="200px" show-overflow-tooltip></el-table-column>
      <el-table-column label="发起人" prop="userName" align="center" width="80px" show-overflow-tooltip></el-table-column>
      <el-table-column label="任务数量" prop="cou" align="center" width="90px" show-overflow-tooltip>
        <template slot-scope="scope">
          <span v-if="scope.row.cou == 0">1</span>
          <span v-else>{{scope.row.cou}}</span>
        </template>
      </el-table-column>
      <el-table-column label="接收时间" prop="time" align="center" width="150px" show-overflow-tooltip>
        <template slot-scope="scope">{{$moment(scope.row.time).format("YYYY-MM-DD HH:mm")}}</template>
      </el-table-column>
      <el-table-column label="操作" align="center" min-width="100">
        <template slot-scope="scope">
          <el-button type="primary" plain @click="handleDialog(scope.row,'待办')">审批办理</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div v-if="false" class="avue-crud__pagination">
      <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex"
                     :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage" background
                     layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>
    </div>
    <!-- <workflow ref="workflow" @refreshDataList="getDataList" @refreshTableData="getDataList"></workflow> -->
    <jiangjinWork ref="jiangjinWork" @jiangChild='jiangChild'></jiangjinWork>
  </div>
</template>

<script>
import {jjdb,wddbpage} from "@/api/workflow/wfywmain";
import jiangjinWork from '@/views/workflow/apply/jiangjinWork'

import store from '@/store'
import {
  mapGetters
} from 'vuex'

export default {
  data() {
    return {
      dataForm: {
        key: ''
      },
      dataFormSzbg: {
        id: 0,
        szbgFjmc: '',
        szbgFjlx: '',
        szbgFjdz: '',
        szJzDate: ''
      },
      bgdialogVisible: false,
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      addOrUpdateVisible: false,
      cepinghdgulszbgUploadFormVisible: false,
      headers: {
        Authorization: 'Bearer ' + store.getters.access_token
      },
      bgUrl: ""
    }
  },
  created() {
    this.getDataList();
  },
  computed: {
    ...mapGetters(['permissions'])
  },
  props: {
    tableHeight: {
      type: String,
      default: null
    }
  },
  components: {
    jiangjinWork
  },
  methods: {
    formater(row, column, cellValue, index) {
      if (cellValue) {
        return this.$moment(cellValue).format("yyyy-MM-DD HH:mm");
      } else {
        return cellValue;
      }
    },
    // 获取数据列表 预览分页查询使用
    getDataList() {
      this.dataListLoading = true
      jjdb(Object.assign({
        current: this.pageIndex,
        size: this.pageSize
      })).then(response => {
        var jjDataList = response.data.data.records
        //使用合同的那个接口然后根据条件来筛选奖金的
        wddbpage(Object.assign({
          current: this.pageIndex,
          size: this.pageSize,
          key:"JJ_FP,JJ_FF"
        })).then(res => {
          this.dataList =jjDataList.map(item=>{
            var temp={};
            var todoObj=res.data.data.records.find(jjItem=>jjItem.taskId==item.taskId);
            if(todoObj){
              temp=Object.assign(item,todoObj)
            }else{
              temp=item;
            }
            return temp;
          })
          this.totalPage = res.data.data.total
        })
      })

      this.dataListLoading = false
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val
      this.getDataList()
    },
    handleDialog(r, text) {
      if(r.nodeKey=='jjfftjsj'){
        this.$router.push({ path: "/jiangjin/jiangjinfpjjfpdjb/jigou" ,query:{id:r.id}});
      }else{
        this.$router.push({path:'/jiangjin/bonusReview/index',query: {r:r,text:text}})
      }
      
      // this.$nextTick(() => {
      //   this.$refs.jiangjinWork.open(r.fpId, r.taskId, r['processInstanceId'], r.type, text)
      // })
    },
    jiangChild(result) {
      this.getDataList();
      this.$emit('jiangjinTdChild')
    },
  }
}

</script>
